package com.hu.hutool.json;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hu.hutool.entity.Cat;
import com.hu.hutool.entity.User;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author CazCen
 * @Date 2021/11/18 9:29
 */
@Slf4j
public class JSONObjectTest {

    /**
     * 使用JSONUtil创建JsonObject
     */

    public static JSONObject jsonObject() {
        Map<String, Object> map = new HashMap<>(10);

        Cat cat = new Cat();
        cat.setEyeNumber(2);
        cat.setFootNumber(4);
        cat.setMouseNumber(1);
        cat.setWeightNumber(110);

        map.put("map_key1", cat);
        JSONObject obj = JSONUtil.createObj();
        obj.putAll(map);

        return obj;
    }

    public static void jsonObjectMap() {

        Map<String, Object> map = new HashMap<>(10);
        map.put("map_key1", "map_value1");
        map.put("map_key2", "map_value2");
        map.put("map_key3", "map_value3");
        map.put("map_key4", "map_value4");

        JSONObject obj = JSONUtil.createObj();
        obj.putAll(map);

        log.info("JsonObj:{}", obj);

    }


    /**
     * JsonArray
     */
    public static void jsonArray() {
        List<Object> list = new ArrayList<>();
        list.add("a");
        list.add(1);
        User user = new User();
        user.setAge(10);
        list.add(user);

        Cat cat = new Cat();
        cat.setEyeNumber(2);
        cat.setFootNumber(4);
        cat.setMouseNumber(1);
        cat.setWeightNumber(110);

        list.add(cat);

        JSONArray jsonArray = new JSONArray(list);
        log.info("jsonArray:{}", jsonArray);

    }


    /**
     * JsonObject 转小写
     */
    public static void JsonObjectToLowercase(JSONObject obj) {

    }

}
